#pragma once
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <d3d9.h>
#include "camera.h"
#include "matrix.h"
#include "image.h"
#include "texture.h"
#include "rawdataresource.h"
#include "triangle.h"

/**
 * Klasa grafiki.
 *
 * @author Krzysztof Klein
 * @version 0.1
 */
class Graphics
{
	LPDIRECT3D9 d3d;
	LPDIRECT3DDEVICE9 device;
	LPDIRECT3DSURFACE9 renderTarget;
	Camera* camera;
	Image* fontImage;
	RawDataResource* fontMetrics;
	mutable Matrix world, view, proj;
	mutable Matrix worldViewProj;

public:

	/**
	 * Konstruktor domyslny
	 */
	Graphics() : d3d(NULL), device(NULL), renderTarget(NULL) { }

	/**
	 * Destruktor
	 */
	~Graphics() { close(); }

	bool initialize();
	void close();

	bool beginDrawing(bool clear = true) const;
	void endDrawing() const;
	void beginScene() const;
	void endScene() const;

	LPDIRECT3DDEVICE9 getDevice() const { return device; }
	Camera* getCamera() const { return camera; }

	void drawImage(const Image &image) const;
	void drawImage(const Image &image, int x, int y) const;
	void drawImage(const Image &image, int x, int y, float width, float height) const;

	void draw2DTexture(const Texture &tex, float x, float y, float w, float h, BYTE r, BYTE g, BYTE b, BYTE a) const;

	void drawWireframeBox(const Vector &min, const Vector &max) const;

	void drawWireframeTriangle(const Triangle &tri) const;

	void drawText(int x, int y, const std::string &text);
	void drawText(int x, int y, const char* text);

	void setWorldTransformation(const Matrix &mtx) const;
	void setViewTransformation(const Matrix &mtx) const;
	void setProjectionTransformation(const Matrix &mtx) const;

	/*
	const Matrix& getWorldMatrix() const { return world; }
	const Matrix& getViewMatrix() const { return view; }
	const Matrix& getProjectionMatrix() const { return proj; }
	const Matrix& getWorldViewProjectionMatrix() const { return worldViewProj; }
	*/
};
